home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6414 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  36 lines

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: automatic charrs
  5. Date: 24 Feb 1996 17:11:55 GMT
  6. Organization: systems hk
  7. Message-ID: <4gngsr$8jr@maureen.teleport.com>
  8. References: <4glp29$dsh@d2.tufts.edu>
  9. NNTP-Posting-Host: ip-pdx13-51.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. rdorich@emerald.tufts.edu (Roberto Dorich) wrote:
  16. >Could someone enlighten me, and tell me why the following program runs
  17. >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
  18. >
  19. >#include <stdio.h>
  20. >char *b() { return "Hello";}
  21. >main() {
  22. >  char *a=b();
  23. >  a[0]='X';
  24. >  printf("--> %s\n",a);
  25. >}
  26. [snip]
  27. Roberto
  28. Since a is a pointer to a character, and is initialized to the
  29. return value of b(), it contains a ptr to the string "Hello"
  30. which may or may not be in transitory or read-only memory,
  31. depending on the environment. Therefore, setting the first character
  32. to 'X' may generate an access violation.
  33. Yours, Geoff Houck
  34.  
  35.  
  36.